package com.haiberg.framework.util;

import java.lang.reflect.Method;

public class ReflectionUtil {
	
	public static boolean isShow = true;	//是否启用
 
	/**
	 * 获得一个对象的属性值
	 * @author:qiuchen
	 * @createTime:2012-7-4
	 * @param obj 目标对象
	 */
	@SuppressWarnings("unchecked")
	public static void getFieldValue(Object obj){
		if (isShow) getFieldValue(obj, isShow);
	}
	
	/**
	 * 获得一个对象的属性值
	 * @author:qiuchen
	 * @createTime:2012-7-4
	 * @param obj 目标对象
	 */
	@SuppressWarnings("unchecked")
	private static void getFieldValue(Object obj,boolean isShow){
		Class cls = obj.getClass();
        Method[] methods = cls.getDeclaredMethods();//获得类的方法集合
        StringBuffer buffer = new StringBuffer();
        try {
        	for (Method method : methods) {
				if(method!=null && method.getName().startsWith("get")){
					Object value = method.invoke(obj, null);
					value = method.getName().substring(3)+":"+value+","; 
					buffer.append(value);
				}
			}
        } catch (Exception e) {
        	e.printStackTrace();
        }
        System.out.println(cls.toString()+"["+buffer.toString()+"]");
	}
	
	public static void main(String[] args) {
		
	}
	
}